package org.jaaksi.kottlindemo.home

import android.annotation.SuppressLint
import android.app.Activity
import android.app.Application.ActivityLifecycleCallbacks
import android.os.Bundle
import timber.log.Timber

@SuppressLint("StaticFieldLeak")
object AppLifecycleCallbacks : ActivityLifecycleCallbacks {

    var topActivity: Activity? = null

    override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
        topActivity = activity
        Timber.e("onActivityCreated activity = $activity")
    }

    override fun onActivityStarted(activity: Activity) {
        topActivity = activity
        Timber.e("onActivityStarted activity = $activity")
    }

    override fun onActivityResumed(activity: Activity) {
        topActivity = activity
        Timber.e("onActivityResumed activity = $activity")
    }

    override fun onActivityPaused(activity: Activity) {

    }

    override fun onActivityStopped(activity: Activity) {

    }

    override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {

    }

    override fun onActivityDestroyed(activity: Activity) {
        Timber.e("onActivityDestroyed topActivity = $topActivity activity = $activity")
        if (topActivity == activity) {
            topActivity = null
        }

    }

}